class CommissionPolicyGroup {
    String name
    static hasMany = [commissionPolicys:CommissionPolicy, staffs:Staff]

    String toString(){
        return name
    }

    CommissionPolicy searchCommissionPolicyByProduct(Product product){
        commissionPolicys.find {CommissionPolicy commissionPolicy->
            boolean productMatched = commissionPolicy.product && product.id == commissionPolicy.product.id
            if (productMatched)
                return true

            boolean productCategoryMatched = commissionPolicy.productCategory && product.productCategory.id == commissionPolicy.productCategory.id
            if (productCategoryMatched)
                return true

            return false
        }
    }

}
